/* This file wraps ESourceGroup class */
%module "evolution"
%{
#include <libedataserver/e-source-group.h>	
%}

struct ESourceGroup 
{
};

%extend ESourceGroup
{
        ESourceGroup (const char* name, const char* uri) {
               return e_source_group_new(name, uri);
        }

		ESourceGroup* dup (){
			return e_source_group_new_from_xml(e_source_group_to_xml(self));
		}

        ESource* __getitem__(int index) {
            ESource *source = NULL;
            source=E_SOURCE(g_slist_nth_data(e_source_group_peek_sources(self),index));
			if(source)
				g_object_ref(source);   
            return source;   
        }

        int __len__() {
            return g_slist_length(e_source_group_peek_sources(self));
        }

        ESourceGroup* insert(int index, ESource* src) {
            /*This already refs the ESource*/
			e_source_group_add_source(self, src, index);            
			VALUE rb1 = (VALUE)g_object_get_data(G_OBJECT(src), "RUBY_PTR");
			if(!rb1)
				rb_warn("ESource 1 sin ruby");
			ESource* source = e_source_group_peek_source_by_uid (self, e_source_peek_uid (src));
			rb1 = (VALUE)g_object_get_data(G_OBJECT(source), "RUBY_PTR");
			if(!rb1)
				rb_warn("ESource 2 sin ruby");
            return self;   
        }
	
		ESourceGroup* append(ESource* src) {
			return ESourceGroup_insert(self, -1, src);   
		}

		bool __eq__(ESourceGroup* grp)
		{
			return (strcmp(e_source_group_peek_uid(self), e_source_group_peek_uid(grp))==0);
		}
		char* to_xml(){
		  return e_source_group_to_xml(self);
		}
};

DEFINE_DEFAULT_DESTRUCTOR(ESourceGroup);
PROPERTY_RW(ESourceGroup, readonly, gboolean, e_source_group_get_readonly, e_source_group_set_readonly)
PROPERTY_RW(ESourceGroup, name, const char*, e_source_group_peek_name, e_source_group_set_name)
PROPERTY_RW(ESourceGroup, base_uri, const char*, e_source_group_peek_base_uri, e_source_group_set_base_uri)
PROPERTY_READ(ESourceGroup, uid, const char*, e_source_group_peek_uid)


